﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Globalization;
using Public;

namespace WebsiteAdmin.Salomon.ProInfo.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ProUpdate : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int rtn = 0;
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")
            {
                int txbPKID = Convert.ToInt32(context.Request["PKID"].Trim(), CultureInfo.InvariantCulture);
                string txbProName = context.Request["ProName"].Trim();
                string txbKeywords = context.Request["Keywords"].Trim();
                string txbDescription = context.Request["Description"].Trim();
                string txbProCode = context.Request["ProCode"].Trim();
                string txbImgURL = context.Request["ImgURL"].Trim();
                string txbThumbURL = context.Request["ImgURL"].Trim();
                int txbCatID = Convert.ToInt32(context.Request["CatID"].Trim(), CultureInfo.InvariantCulture);
                int txbSerID = Convert.ToInt32(context.Request["SerID"].Trim(), CultureInfo.InvariantCulture);
                int txbSortBy = Convert.ToInt32(context.Request["SortBy"].Trim(), CultureInfo.InvariantCulture);	//显示顺序
                string txbProContent = context.Request["ProContent"].Trim();

                rtn = DoUpdate(
                    txbProName,
                    txbKeywords,
                    txbDescription,
                    txbProCode,
                    txbThumbURL,
                    txbImgURL,
                    txbCatID,
                    txbSerID,
                    txbProContent,
                    txbSortBy,
                    txbPKID
                );
            }
            context.Response.Write((rtn == 1) ? "{ \"Done\": \"Success\" }" : "{ \"Done\": \"Failed\" }");
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private static int DoUpdate(
                string txbProName,
                string txbKeywords,
                string txbDescription,
                string txbProCode,
                string txbThumbURL,
                string txbImgURL,
                int txbCatID,
                int txbSerID,
                string txbProContent,
                int txbSortBy,
                int txbPKID
            )
        {
            return
                Bll.Product.Update(
                    Global.ConSalomon,
                    txbProName,
                    txbKeywords,
                    txbDescription,
                    txbProCode,
                    txbThumbURL,
                    txbImgURL,
                    txbCatID,
                    txbSerID,
                    txbProContent,
                    txbSortBy,
                    txbPKID
                );
        }

    }
}
